package io.hxci.modules.zhangcong.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.hxci.common.annotation.DataFilter;
import io.hxci.common.utils.Constant;
import io.hxci.common.utils.PageUtils;
import io.hxci.common.utils.Query;
import io.hxci.modules.sys.entity.SysDeptEntity;
import io.hxci.modules.sys.entity.SysUserEntity;
import io.hxci.modules.zhangcong.domain.Zcdict;
import io.hxci.modules.zhangcong.service.ZcdictService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.hxci.modules.zhangcong.domain.Zcuser;
import io.hxci.modules.zhangcong.dao.ZcuserMapper;
import io.hxci.modules.zhangcong.service.ZcuserService;
@Service
public class ZcuserServiceImpl extends ServiceImpl<ZcuserMapper, Zcuser> implements ZcuserService {
    @Autowired
    ZcdictService zcdictService;


    //@DataFilter(subDept = true, user = false)
    @Override
    public PageUtils queryPage(Map<String, Object> zcparams) {
        String zcname = (String)zcparams.get("zcusername");
        IPage<Zcuser> page = this.page(
                new Query<Zcuser>().getPage(zcparams),
                new QueryWrapper<Zcuser>()
                        .like(StringUtils.isNotBlank(zcname),"username", zcname)
                        .orderByDesc("create_time")
                       // .apply(zcparams.get(Constant.SQL_FILTER) != null, (String)zcparams.get(Constant.SQL_FILTER))
         );

        for(Zcuser user : page.getRecords()){
            Zcdict zcdict = zcdictService.getById(user.getZzmm());
            Zcdict zcdict2 = zcdictService.getById(user.getZc());
            user.setZmname(zcdict.getValue());
            user.setZcname(zcdict2.getValue());
        }

        return  new PageUtils(page);
    }
}
